package org.hepeng.hope.entity

import org.hibernate.annotations.ColumnDefault
import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.ConstraintMode.*
import javax.persistence.Entity
import javax.persistence.ForeignKey
import javax.persistence.JoinColumn
import javax.persistence.OneToOne
import javax.persistence.Table
import javax.persistence.UniqueConstraint
import org.hepeng.hope.entity.Entity as E

const val AUTHORITY_TABLE_NAME = "authority"

@Entity
@Table(name = AUTHORITY_TABLE_NAME , uniqueConstraints = [UniqueConstraint(columnNames = ["name"])])
internal data class Authority(@Column(name = "`name`" , length = 200 , nullable = false) var name: String ,
                              @Column(name = "`desc`" , length = 500) @ColumnDefault("''") var desc: String
) : E() {

    @OneToOne(/*mappedBy = "authorityId" , */cascade = [CascadeType.ALL])
    @JoinColumn(name = "authorityId" , foreignKey = ForeignKey(NO_CONSTRAINT))
    lateinit var uiResources: UIResources
}